<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

    <style type="text/css" media="screen">
        @import url("<c:url value="/resources/dojo/resources/dojo.css"/>");
        @import url("<c:url value="/resources/dijit/themes/tundra/tundra.css"/>");
        @import url("<c:url value="/static/styles/finance.css"/>");
    </style>

    <script djconfig="parseOnLoad: true" src="<c:url value="/resources/dojo/dojo.js"/>" type="text/javascript"></script>
    <script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"></script>
    <script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"></script>
    <script type="text/javascript">dojo.require("dojo.parser");</script>
    <title>Spring Finance</title>

</head>

<body class="tundra spring">

<div id="wrap">

    <div id="menu">
        <%@ include file="/WEB-INF/jsp/menu.jsp" %>
    </div>
    <div id="main">
        <div id="body">


            <script type="text/javascript">dojo.require("dijit.TitlePane");</script>
            <div dojoType="dijit.TitlePane" style="width: 100%" title="List All Accounts">
                <c:if test="${not empty accounts}">
                    <table width="300px">
                        <thead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Owners</th>
                            <th>Manager</th>
                            <th>Investments</th>
                            <th/>
                            <th/>
                            <th/>
                        </tr>
                        </thead>
                        <c:forEach items="${accounts}" var="account">
                            <tr>
                                <td>${account.id}</td>
                                <td>${fn:substring(account.name, 0, 10)}</td>
                                <td>${fn:length(account.owners)}</td>
                                <td>${fn:substring(account.manager, 0, 10)}</td>
                                <td>${fn:length(account.investments)}</td>
                                <td>
                                    <form:form action="/account/${account.id}" method="GET">
                                        <input alt="Show Account" src="/static/images/show.png"
                                               title="Show Account" type="image" value="Show Account"/>
                                    </form:form>
                                </td>
                                <sec:authorize ifAllGranted="ROLE_ADMIN">
                                    <td>
                                        <form:form action="/account/${account.id}/form" method="GET">
                                            <input alt="Update Account" src="/static/images/update.png"
                                                   title="Update Account" type="image" value="Update Account"/>
                                        </form:form>
                                    </td>
                                    <td>
                                        <form:form action="/account/${account.id}" method="DELETE">
                                            <input alt="Delete Account" src="/static/images/delete.png"
                                                   title="Delete Account" type="image" value="Delete Account"/>
                                        </form:form>
                                    </td>
                                </sec:authorize>
                            </tr>
                        </c:forEach>
                    </table>
                </c:if>
                <c:if test="${empty accounts}">No accounts found.</c:if>
            </div>
        </div>
        <table class="footer">
            <tr>
                <td><a href="<c:url value="/" />">Home</a></td>
                <td align="right"><a href="http://stsmedia.net" alt="StSMedia.net">StSMedia.net</a></td>
            </tr>
        </table>

    </div>
</div>
</body>

</html>